﻿using System;
using System.Collections;
using FlowCanvas;
using FlowCanvas.Nodes;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using UnityEngine.Playables;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    [Category("Ggame")]
    public class PlayEnterCityCamera : LatentActionNodeBase
    {
        
        [HideInInspector]
        public FlowOutput onStop;
        
        private bool stopped = false;

        public override bool allowRoutineQueueing { get { return false; } }

        public IEnumerator Invoke()
        {
            stopped = false;
            BlueprintUtils.PlayEnterCityCamera(OnStopped);
            yield return new UnityEngine.WaitUntil(() =>
            {
                return stopped;
            });
        }
        
        private void OnStopped(PlayableDirector director)
        {
            onStop?.Call(new Flow());
            stopped = true;
        }

        protected override void OnRegisterDerivedPorts(FlowNode node)
        {
            onStop = node.AddFlowOutput("onStop");
            
            node.AddFlowInput("In", (f) => { Begin(Invoke(), f); });
        }
    }
}